
import {Injectable} from "@angular/core";
import {User} from "../models/user-model";
import {AppService} from "./app.service";
import {ResDataModel} from "../models/res-data-model";
//import {Observable} from "rxjs/Observable";
//import { of } from 'rxjs/observable/of';

@Injectable()
export class UserInfoService {

  private _user:User = new User();

  constructor(public appService: AppService){

  }

  get user(): User {
    return this._user;
  }

  set user(value: User) {
    this._user = value;
  }

  //服务端更新用户信息
  updateUserToServer(successCallback?,failCallback?) {
    // if(user){
    //   user = this.user;
    // }
    let postData = {
      form_user:{
        nickName: this.user.nickName,
        userName: this.user.userName,
        xb:this.user.gender,
        mail:this.user.mail,
        sjhm:this.user.mobileNumber,
        csrq:this.user.birthday,
        xzqhDm:this.user.areaCode
      }
    }

    this.appService.httpPost('AppUserCtrl_updateMyInfo',postData,null,(res:ResDataModel)=>{
      var flag = res.datas[1].value;
      if(flag == "success"){
        //后台保存成功
        this.appService.smallToast("保存成功");
        if(successCallback){
          successCallback(res.datas);
        }
      } else {
        this.appService.smallToast("保存失败","warning");
        failCallback(res.datas);
      }
    },true)
  }
}
